home *** CD-ROM | disk | FTP | other *** search
/ Freelog 119 / FreelogNo119-MarsAvril2014.iso / Securite / Malwarebytes Anti-Malware / mbam-setup-1.75.0.1300.exe / {app} / Chameleon / chameleon.chm / js / jquery.main.js < prev   
Text File  |  2012-03-03  |  6KB  |  199 lines

  1. $(function(){
  2.     clearInputs();
  3.     initNav();
  4.     initPlugins();
  5. });
  6.  
  7. function initNav(){
  8.     var duration = 500;
  9.     $('#nav > li').each(function(){
  10.         var holder = $(this);
  11.         var drop = $('div.drop',holder);
  12.         var list = $('>ul',drop);
  13.         
  14.         holder.mouseenter(function(){
  15.             if (drop.is(':hidden')) {
  16.                 drop.show();
  17.                 list.css({marginTop:-list.outerHeight()}).animate({marginTop:0},duration);
  18.             } else {
  19.                 list.stop().animate({marginTop:0},duration);
  20.             }
  21.         }).mouseleave(function(){
  22.             list.stop().animate({marginTop:-list.outerHeight()},duration,function(){
  23.                 drop.hide();
  24.             });
  25.         });
  26.     });
  27. }
  28.  
  29. function clearInputs()
  30. {
  31.     clearFormFields({
  32.         clearInputs: true,
  33.         clearTextareas: true,
  34.         passwordFieldText: true,
  35.         addClassFocus: "focus",
  36.         filterClass: "default"
  37.     });
  38. }
  39. function clearFormFields(o)
  40. {
  41.     if (o.clearInputs == null) o.clearInputs = true;
  42.     if (o.clearTextareas == null) o.clearTextareas = true;
  43.     if (o.passwordFieldText == null) o.passwordFieldText = false;
  44.     if (o.addClassFocus == null) o.addClassFocus = false;
  45.     if (!o.filterClass) o.filterClass = "default";
  46.     if(o.clearInputs) {
  47.         var inputs = document.getElementsByTagName("input");
  48.         for (var i = 0; i < inputs.length; i++ ) {
  49.             if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass) == -1) {
  50.                 inputs[i].valueHtml = inputs[i].value;
  51.                 inputs[i].onfocus = function ()    {
  52.                     if(this.valueHtml == this.value) this.value = "";
  53.                     if(this.fake) {
  54.                         inputsSwap(this, this.previousSibling);
  55.                         this.previousSibling.focus();
  56.                     }
  57.                     if(o.addClassFocus && !this.fake) {
  58.                         this.className += " " + o.addClassFocus;
  59.                         this.parentNode.className += " parent-" + o.addClassFocus;
  60.                     }
  61.                 }
  62.                 inputs[i].onblur = function () {
  63.                     if(this.value == "") {
  64.                         this.value = this.valueHtml;
  65.                         if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
  66.                     }
  67.                     if(o.addClassFocus) {
  68.                         this.className = this.className.replace(o.addClassFocus, "");
  69.                         this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
  70.                     }
  71.                 }
  72.                 if(o.passwordFieldText && inputs[i].type == "password") {
  73.                     var fakeInput = document.createElement("input");
  74.                     fakeInput.type = "text";
  75.                     fakeInput.value = inputs[i].value;
  76.                     fakeInput.className = inputs[i].className;
  77.                     fakeInput.fake = true;
  78.                     inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
  79.                     inputsSwap(inputs[i], null);
  80.                 }
  81.             }
  82.         }
  83.     }
  84.     if(o.clearTextareas) {
  85.         var textareas = document.getElementsByTagName("textarea");
  86.         for(var i=0; i<textareas.length; i++) {
  87.             if(textareas[i].className.indexOf(o.filterClass) == -1) {
  88.                 textareas[i].valueHtml = textareas[i].value;
  89.                 textareas[i].onfocus = function() {
  90.                     if(this.value == this.valueHtml) this.value = "";
  91.                     if(o.addClassFocus) {
  92.                         this.className += " " + o.addClassFocus;
  93.                         this.parentNode.className += " parent-" + o.addClassFocus;
  94.                     }
  95.                 }
  96.                 textareas[i].onblur = function() {
  97.                     if(this.value == "") this.value = this.valueHtml;
  98.                     if(o.addClassFocus) {
  99.                         this.className = this.className.replace(o.addClassFocus, "");
  100.                         this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
  101.                     }
  102.                 }
  103.             }
  104.         }
  105.     }
  106.     function inputsSwap(el, el2) {
  107.         if(el) el.style.display = "none";
  108.         if(el2) el2.style.display = "inline";
  109.     }
  110. }
  111. // plugins init
  112. function initPlugins(){
  113.     jQuery('ul.tabset').jqueryTabs({
  114.         addToParent:false,
  115.         holdHeight:false,
  116.         activeClass:'active',
  117.         tabLinks:'a.tab',
  118.         fadeSpeed:0
  119.     });
  120. }
  121.  
  122. // jquery tabs plugin
  123. jQuery.fn.jqueryTabs = function(_options){
  124.     // default options
  125.     var _options = jQuery.extend({
  126.         addToParent:false,
  127.         holdHeight:false,
  128.         activeClass:'active',
  129.         tabLinks:'a.tab',
  130.         fadeSpeed:300,
  131.         event:'click'
  132.     },_options);
  133.  
  134.     return this.each(function(){
  135.         var _holder = jQuery(this);
  136.         var _fadeSpeed = _options.fadeSpeed;
  137.         var _activeClass = _options.activeClass;
  138.         var _addToParent = _options.addToParent;
  139.         var _holdHeight = _options.holdHeight;
  140.         var _tabLinks = jQuery(_options.tabLinks, _holder);
  141.         var _tabset = (_addToParent ? _tabLinks.parent() : _tabLinks);
  142.         var _event = _options.event;
  143.         var _animating = false;
  144.  
  145.         // tabs init
  146.         _tabLinks.each(function(){
  147.             var _tmpLink = jQuery(this);
  148.             var _tmpTab = jQuery(_tmpLink.attr('href'));
  149.             var _classItem = (_addToParent ? _tmpLink.parent() : _tmpLink);
  150.             if(_tmpTab.length) {
  151.                 if(_classItem.hasClass(_activeClass)) _tmpTab.show();
  152.                 else _tmpTab.hide();
  153.             }
  154.         });
  155.  
  156.         // tab switcher
  157.         function switchTab(_switcher) {
  158.             if(!_animating) {
  159.                 var _link = jQuery(_switcher);
  160.                 var _newItem = (_addToParent ? _link.parent() : _link);
  161.                 var _newTab = jQuery(_link.attr('href'));
  162.                 if(_newItem.hasClass(_activeClass)) return;
  163.  
  164.                 var _oldItem = jQuery(_addToParent ? _tabset : _tabLinks).filter('.'+_activeClass);
  165.                 var _oldTab = jQuery(jQuery(_addToParent ? _oldItem.children('a') : _oldItem).attr('href'));
  166.                 if(_newTab.length) {
  167.                     _animating = true;
  168.                     if(_oldItem.length) {
  169.                         _newItem.addClass(_activeClass);
  170.                         _oldItem.removeClass(_activeClass);
  171.  
  172.                         var _parent = _oldTab.parent();
  173.                         if(_holdHeight) _parent.css({height:_parent.height()});
  174.  
  175.                         _oldTab.fadeOut(_fadeSpeed,function(){
  176.                             _newTab.fadeIn(_fadeSpeed,function(){
  177.                                 _animating = false;
  178.                             });
  179.                             if(_holdHeight) _parent.css({height:'auto'});
  180.                         });
  181.                     } else {
  182.                         _newItem.addClass(_activeClass);
  183.                         _newTab.fadeIn(_fadeSpeed,function(){
  184.                             _animating = false;
  185.                         });
  186.                     }
  187.                 }
  188.             }
  189.         }
  190.  
  191.         // control
  192.         _tabLinks.each(function(){
  193.             jQuery(this).bind(_event,function(){
  194.                 switchTab(this);
  195.                 return false;
  196.             });
  197.         });
  198.     });
  199. }